package net.bgraham.collectionbatcher;

import net.bgraham.collectionbatcher.Log;

public class Util
{
	public static void printBatchStats(long batches, long fullTimeoutCount, long earlyTimeoutCount)
	{
		Log.log("batches = " + batches + " : fullTimeoutCount = " + fullTimeoutCount + " : earlyTimeoutCount = " + earlyTimeoutCount);
	}

	public static void printResults(long expected, long received)
	{
		Log.log("received " + received + "/" + expected + " : lost = " + (expected - received));
	}
	
	public static void doSleep(long millis)
	{
		try
		{
			Thread.sleep(millis);
		} catch (InterruptedException e)
		{ }
	}
	
	public static class CellInfo implements Comparable<CellInfo>
	{
		private int row;
		private int col;
		
		public CellInfo(int row, int col)
		{
			this.row = row;
			this.col = col;
		}
		
        public boolean equals(Object o)
        {
            if (!(o instanceof CellInfo))
                return false;
            
            CellInfo cellInfo = (CellInfo)o;
            return row == cellInfo.row && col == cellInfo.col;
        }
    
        public int hashCode()
        {
            return (row * col);
        }
        
        public String toString()
        {
        	return "[" + row + ", " + col + "]";
        }

		public int getRow()
		{
			return row;
		}

		public void setRow(int row)
		{
			this.row = row;
		}

		public int getCol()
		{
			return col;
		}

		public void setCol(int col)
		{
			this.col = col;
		}

		public int compareTo(CellInfo o)
		{
			if (row < o.getRow())
			{
				return -1;
			}
			else if (row > o.getRow())
			{
				return 1;
			}
			else
			{
				// rows are the same, check cols
				if (col < o.getCol())
				{
					return -1;
				}
				else if (col > o.getCol())
				{
					return 1;
				}
				else
				{
					return 0;
				}
			}
		}
	}
}
